package cn.bellychang.didi;

import cn.bellychang.leetcode.question019.ListNode;

import java.util.HashSet;

/**
 * @author ChangLiang
 * @date 2021/3/11
 */
public class Solution {

    public boolean haveSharedNode(ListNode node1, ListNode node2){

        HashSet<ListNode> set = new HashSet<>();
        while (node1 != null) {
            set.add(node1);
            node1 = node1.next;
        }

        while (node2 != null) {
            if (set.contains(node2)) {
                return true;
            }
            node2 = node2.next;
        }
        return false;
    }
}
